<!--
 * @Description: 创建班级排行查看详情弹窗
 * @Author: liyujie
 * @Date: 2021/07/27
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/07/27
-->
<template>
    <section class="wrapper">
        <el-dialog
            title="查看详情（包含精英的收益和直属/间接精英提供的佣金数据）"
            :visible.sync="dialogVisible"
            width="1250px"
            :close-on-click-modal="false"
        >
            <div class="dialog-content">
                <div class="filter-view">
                    <div class="header-new-box">
                        <p class="header-new-box-title">
                            创建人
                        </p>
                        <el-input
                            placeholder="请输入用户编号/手机号"
                            v-model="filterData.keyword"
                            suffix-icon="el-icon-search"
                            clearable
                            size="medium"
                            style="width: 260px"
                            @keydown.enter.native="getTableData(1)"
                        />
                    </div>
                    <div class="header-new-box">
                        <p class="header-new-box-title">
                            收入类型
                        </p>
                        <el-select
                            placeholder="全部"
                            v-model="filterData.award_type"
                            size="medium"
                            style="width: 194px"
                            @change="getTableData(1)"
                        >
                            <el-option
                                v-for="item in awardTypeList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </div>
                    <div class="header-new-box">
                        <p class="header-new-box-title">
                            注册时间
                        </p>
                        <el-date-picker
                            v-model="registerDateTimeRange"
                            type="datetimerange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00', '23:59:59']"
                            size="medium"
                            style="width: 360px"
                            value-format="timestamp"
                            @change="getTableData(1)"
                        />
                    </div>
                    <div class="header-new-box">
                        <p class="header-new-box-title">
                            奖励到账时间
                        </p>
                        <el-date-picker
                            v-model="awardDateTimeRange"
                            type="datetimerange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00', '23:59:59']"
                            size="medium"
                            style="width: 360px"
                            value-format="timestamp"
                            @change="getTableData(1)"
                        />
                    </div>
                    <div class="header-new-box">
                        <el-button
                            type="primary"
                            size="small"
                            class="query-button"
                            @click="getTableData(1)"
                        >
                            查询
                        </el-button>
                        <el-button
                            type="text"
                            @click="handleReset()"
                        >
                            重置
                        </el-button>
                    </div>
                </div>
                <div class="table-wrapper">
                    <el-table
                        :data="tableData"
                        height="100%"
                        style="width: 100%;"
                        ref="table"
                        class="data-table"
                        :cell-style="{height: '40px'}"
                        v-loading="tableLoading"
                    >
                        <el-table-column
                            label="序号"
                            align="center"
                            width="50"
                            type="index"
                        />
                        <el-table-column
                            label="创建人信息"
                            width="200"
                            :formatter="emptyFormatter"
                        >
                            <template slot-scope="scope">
                                <div class="cell-title">{{ scope.row.true_name ? scope.row.true_name : '--' }}</div>
                                <div class="cell-tips">手机号：{{ scope.row.phone }}</div>
                                <div class="cell-tips">用户ID：{{ scope.row.student_no }}</div>
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="注册时间"
                            align="left"
                            width="160"
                            :formatter="emptyFormatter"
                        >
                            <template slot-scope="scope">
                                {{ scope.row.register_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="school_name"
                            label="学校信息"
                            width="140"
                            :formatter="emptyFormatter"
                        >
                            <template slot-scope="scope">
                                {{ scope.row.school_name }} / {{ scope.row.college_name }}
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="major_name"
                            label="专业名称"
                            :formatter="emptyFormatter"
                        />
                        <el-table-column
                            prop="class_name"
                            label="班级名称"
                            align="center"
                            :formatter="emptyFormatter"
                        />
                        <el-table-column
                            prop="enter_school_year"
                            label="入学年份"
                            align="center"
                            :formatter="emptyFormatter"
                        />

                        <el-table-column
                            label="收入类型"
                            align="center"
                            :formatter="emptyFormatter"
                        >
                            <template slot-scope="scope">
                                {{ scope.row.award_type | typeFilter }}
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="实际到账时间"
                            align="left"
                            width="160"
                            :formatter="emptyFormatter"
                        >
                            <template slot-scope="scope">
                                {{ scope.row.award_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="award_money"
                            label="实际获得金额(元)"
                            align="center"
                            width="130"
                            :formatter="emptyFormatter"
                        />
                    </el-table>
                </div>
                <div class="pagination-wrapper clearfix">
                    <el-pagination
                        layout="total, prev, pager, next, jumper"
                        background
                        :current-page.sync="page.now_page"
                        :total="page.total_count"
                        :page-size="page.page_size"
                        @current-change="getTableData"
                    />
                </div>
            </div>
        </el-dialog>
    </section>
</template>

<script>
export default {
    name: "AwardRankDetailDialog",
    data() {
        return {
            dialogVisible: false,
            student_no: '',
            filterData: {
                // 用户编号
                student_no: '',
                // 创建人id电话姓名
                keyword: '',
                // 收入类型99：全部，209：创建同校班级奖励  一级粉丝创建班级奖励，210:二级粉丝创建班级奖励
                award_type: 99,
                // 创建开始时间
                register_start_time: '',
                // 创建结束时间
                register_end_time: '',
                // 奖励到账开始时间
                award_start_time: '',
                // 奖励到账结束时间
                award_end_time: '',
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            registerDateTimeRange: null,
            awardDateTimeRange: null,
            awardTypeList: [
                {label: '全部', value: 99},
                {label: '创建同校班级奖励', value: 212},
                {label: '一级粉丝创建班级奖励', value: 213},
                {label: '二级粉丝创建班级奖励', value: 214},
            ],
        };
    },
    watch: {},
    computed: {},
    filters: {
        typeFilter(val) {
            switch (val) {
                case 212:
                    return '创建同校班级奖励';
                case 213:
                    return '一级粉丝创建班级奖励';
                case 214:
                    return '二级粉丝创建班级奖励';
                default:
                    return '--';
            }
        }
    },
    methods: {
        /**
         * 显示弹窗
         */
        show(student_no) {
            this.filterData.student_no = student_no;
            this.student_no = student_no;
            this.getTableData();
            this.dialogVisible = true;
        },

        /**
         * 显示弹窗
         */
        close() {
            this.dialogVisible = false;
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            params.register_start_time = this.registerDateTimeRange ? this.registerDateTimeRange[0] / 1000 : '';
            params.register_end_time = this.registerDateTimeRange ? this.registerDateTimeRange[1] / 1000 : '';
            params.award_start_time = this.awardDateTimeRange ? this.awardDateTimeRange[0] / 1000 : '';
            params.award_end_time = this.awardDateTimeRange ? this.awardDateTimeRange[1] / 1000 : '';
            this.$post('/student/task_stuagent_extra_class_create%5Cget_user_award_ranking_detail_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData = {
                student_no: this.student_no,
                keyword: '',
                award_type: 99,
                register_start_time: '',
                register_end_time: '',
                award_start_time: '',
                award_end_time: '',
            };
            this.registerDateTimeRange = null;
            this.awardDateTimeRange = null;
            this.getTableData(1);
        },
    }
};
</script>

<style scoped lang="less">
.wrapper {
    .dialog-content {
        display: flex;
        flex-direction: column;
        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            height: 500px;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 2;
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }

    /* 分页 */
    .pagination-wrapper {
        padding: 12px 24px;
        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 24px 32px;
    }
    /deep/ .el-dialog {
        margin-top: 10vh!important;
    }
}
</style>
